/*
 * @Author: your name
 * @Date: 2021-10-13 15:55:58
 * @LastEditTime: 2021-10-30 10:14:59
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /egg_dome/app/middleware/checktoken.js
 */

// 设置白名单
const whiteList = ['/login', '/logins'];

// 中间件鉴权 判断是否需要token验证
module.exports = () => {
    return async (ctx, next) => {
        if(whiteList.includes(ctx.path)) {
            await next()
        } else {
            try {
                let {authorization} = ctx.request.header
                const data = ctx.app.jwt.verify(authorization, ctx.app.config.jwt.secret)
            } catch (error) {
                ctx.body = {
                    code: 501,
                    error: '无token验证'
                }
                return
            }
            await next();
        }
    }
}